import {rewardClass,rewardAll} from "@/api/reward.js"
export default {
	data() {
		return {
			active: 1,
			data: [], //数据列表
			shortTabs:[],
			refresh:false,
			status:"loading",
			page:1,
			tabScrollInto:""
		}
	},
	mounted() {
		rewardClass({split:1}).then(res=>{
			let arr = res.data.filter(item=>{
				return item.type !==3
			})
			this.shortTabs = arr
			this.active = arr[0].id
			this.getPushData();
		})
	},
	//下拉刷新
	onPullDownRefresh() {
		this.status = "nomal"
		this.data = [];
		this.page = 1;
		this.refresh = true;
		this.getPushData()
	},
	//上拉加载
	onReachBottom(){
		this.getPushData()
	},
	methods:{
		handleTab(id) {
			if(this.active === id)return;
			this.active = id;
			this.tabScrollInto = 'item_'+id;
			this.page = 1;
			this.data = [];
			this.getPushData()
		},
		//加载更多数据
		async getPushData(){
			let data = {}
			if(this.active===1){
				data={
					page:this.page,
					size:20,
					recommend:1,
				}
			}else{
				data={
					id:this.active,
					page:this.page,
					size:20,
				}
			}
			let res = await rewardAll(data);
			if(this.refresh){
				uni.stopPullDownRefresh();
				this.refresh = false;
			}
			if(this.page===1&&res.data.length === 0){
				this.status = "nodata"
				return
			}
			if(this.page===1&&res.data.length > 0 && res.data.length < 20){
				this.status = "nomore"
			}
			if(res.data.length === 0){
				this.status = "nomore"
				return;
			}
			
			this.page++;
			this.data = this.data.concat(res.data);
		}
	}
}
